﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IServices.Extension
{
    public class MString
    {
        /// <summary>
        /// 去掉首部和尾部的空字符
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string mTrim(object str)
        {
            if (str == null)
            {
                return string.Empty;
            }
            return str.ToString().Trim();
        }
        /// <summary>
        /// 将字符串转换为日期格式
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime mDataTime(object str)
        {
            if (str == null)
            {
                throw new Exception("错误的日期格式");
            }
            string strVal = Convert.ToString(str);
            DateTime dtResult;
            if (DateTime.TryParse(strVal, out dtResult))
            {
                return dtResult;
            }
            else
            {
                throw new Exception("无法将字符串转换为日期");
            }
        }


    }
}
